package com.hnu.web;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.hnu.model.Bookmark;
import com.hnu.model.User;

public class RecommendBean extends BaseAction {
	private static final long serialVersionUID = 3215543337660924406L;
	private long bookmarkId;
	private List<Bookmark> bookmarkList;
	
	public String contentRecommend()
	{
		String indexPath = ServletActionContext.getRequest().getRealPath("/") + "indexPath";
		List<Bookmark> tempList = this.servLocator.getBookmarkServ().getTopNContentSimilar(bookmarkId, 5, indexPath);
		this.bookmarkList = new ArrayList<Bookmark>();
		for(Bookmark bookmark : tempList)
		{
			if(bookmark.getBookmarkId()!=this.bookmarkId)
			{
				this.bookmarkList.add(bookmark);
			}
		}
		
		return this.returnString();
	}
	
	public String bookmarkRecommend()
	{
		this.bookmarkList = this.servLocator.getBookmarkServ().getBookmarkBasedRecommendBookmark(bookmarkId, 5);
		return this.returnString();
	}
	
	public String returnString()
	{
		User user = (User) this.session.get("user");
		if(user == null)
		{
			return "success";
		}
		else
		{
			return "login";
		}
	}

	public long getBookmarkId() {
		return bookmarkId;
	}

	public void setBookmarkId(long bookmarkId) {
		this.bookmarkId = bookmarkId;
	}

	public List<Bookmark> getBookmarkList() {
		return bookmarkList;
	}

	public void setBookmarkList(List<Bookmark> bookmarkList) {
		this.bookmarkList = bookmarkList;
	}

}
